package 笔试.A2022美团;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

public class third {
    public static void main(String arg[]){//main--来自高金磊

         Scanner scanner=new Scanner(System.in);
         int n=scanner.nextInt();
         int m=scanner.nextInt();
         int data[][]=new int[n][3];
        for (int i = 0; i < n; i++) {
            data[i][0]=scanner.nextInt();
            data[i][1]=scanner.nextInt();
        }
        int[] needs=new int[m+1];//统计需求
        for (int[] datum : data) {
            needs[datum[0]]++;
            needs[datum[1]]++;
        }
        for (int i = 0; i < data.length; i++) {
            data[i][2]=needs[data[i][0]]+needs[data[i][1]];//需求加权
        }
        Arrays.sort(data,(a,b)->(a[2]-b[2]));//排序
        int res=0;
        HashSet<Integer> flag=new HashSet<>();
        for (int[] datum : data) {
            if (flag.contains(datum[0])||flag.contains(datum[1])){
                continue;
            }else {
                res++;
                flag.add(datum[0]);
                flag.add(datum[1]);
            }
        }
        System.out.println(res);

    }
}
